×
☰ See All Chapters

Static polymorphism vs dynamic polymorphism in Java

Static Polymorphism

Dynamic Polymorphism

Also known as compile time polymorphism

Also known as Run time polymorphism

Achieved by method overloading

Achieved by method overriding.

Uses the concept of compile time binding(or early binding) Connecting method call to method body is known as binding.

Uses the concept of runtime binding (or late binding).

Slower than  Dynamic polymorphism

 Faster than static polymorphism.

To implement static polymorphism inheritance is not necessary 

To implement dynamic polymorphism inheritance is necessary.

Java Method Overloading example

package com.java4coding;

 

public class HelloWorld {

        String join(String a, String b) {

                return a + b;

        }

 

        String add(String a, String b, String c) {

                return a + b + c;

        }

}

Java Method Overriding example

class Fruit {

        void color() {

                System.out.println("Color is...");

        }

}

 

class Banana extends Fruit {

        void color() {

                System.out.println("Color is Yellow");

        }

}

 

 


All Chapters
Author